package per.zhang.vaccinesys.serverConsumer.controller;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import per.zhang.vaccinesys.serverConsumer.base.dto.ResultDTO;
import per.zhang.vaccinesys.serverConsumer.base.page.PageList;
import per.zhang.vaccinesys.serverConsumer.base.utils.ResultUtil;
import per.zhang.vaccinesys.serverConsumer.dto.request.VaccineRequsetDTO;
import per.zhang.vaccinesys.serverConsumer.dto.respone.VaccineRespondDTO;
import per.zhang.vaccinesys.serverConsumer.service.VaccineService;

/**
 * @auther zhang
 * @ TO DO
 * @creatTime 2021/1/26 20:38
 **/
@RestController
@RequestMapping("/vaccine")
@CrossOrigin
@Slf4j
public class VaccineController {

    @Autowired
    private VaccineService vaccineService;

    @PostMapping("/selectByUserId")
    @ApiOperation("用户查看疫苗,分页")
    public ResultDTO selectByUserId(@RequestBody VaccineRequsetDTO vaccineRequsetDTO)throws Exception{
        PageList<VaccineRespondDTO> pageData = null;
        ResultDTO<PageList<VaccineRespondDTO>> resultDTO = null;
        try {
            resultDTO = vaccineService.selectByUserId(vaccineRequsetDTO);

            if (resultDTO.getCode().equals("500")) {
                return resultDTO;
            }

            pageData = (PageList<VaccineRespondDTO>)resultDTO.getData();
        } catch (Exception e) {
            return ResultUtil.Error("500",e.getMessage());
        }
        return ResultUtil.Success(pageData);
    }
}
